package com.dong.javaai.tools;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.web.client.RestClient;

import java.net.URI;
import java.util.Map;

public class WeatherTools {

//    public record WeatherRequest(@ToolParam(description = "城市") String city) {
//    }
//
//    public record WeatherResponse(String info) {
//    }

    @Tool(description = "获取当前城市的天气预报")
    public String getWeather(String city) {
        RestClient client = RestClient.create(URI.create("https://api.vvhan.com"));
        Map<?, ?> result = client.get().uri("/api/weather?city={0}", city).retrieve().body(Map.class);
        try {
            return new ObjectMapper().writeValueAsString(result);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }

}
